package com.example.template.commontable.controller;


import com.example.template.commontable.service.impl.CommonTableServiceImpl;
import com.example.template.core.controller.BaseControllerCrud;
import com.example.template.commontable.entity.CommonTable;
import com.example.template.core.controller.BaseModelController;
import com.example.template.core.model.AppJsonMessage;
import com.example.template.core.model.CommonConst;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.List;


/**
* Created by meko on 2019/11/28 09-11-18.
*/
@Api(tags = {"通用表格"})
@RestController
@RequestMapping("/commonTable")
public class CommonTableController extends BaseModelController {

    @Autowired
    private CommonTableServiceImpl commonTableService;

    @ApiOperation(value = "查询所有实体")
    @GetMapping("")
    public AppJsonMessage getAllEntity(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "20") Integer size,
                                       CommonTable t){
        List<CommonTable> dataList = commonTableService.selectAll(t,page,size);
        return this.getJsonMessage(CommonConst.SUCCESS,dataList);
    }

    @ApiOperation(value = "根据实体ID查询实体")
    @GetMapping("/{{tableName}}")
    public AppJsonMessage getEntityByEntity(@PathVariable("{tableName}") String tableName){
        List<LinkedHashMap> columnData = commonTableService.selectColumnData(tableName);
        return this.getJsonMessage(CommonConst.SUCCESS,columnData);
    }
}


